// pages/petsLis/petsLis.js、
import axios from "../../utils/axios";
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    petsList: [],
    loaderShow: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.main()
  },
  main: function () {
    axios('/personal/petsList').then(res => {
      if (res.data.resultcode == '1') {
        this.setData({
          petsList: res.data.result,
          loaderShow: false
        })
      } else if (res.data.resultcode == '0') {
        wx.showToast({
          title: res.data.message
        })
      } else if (res.data.resultcode == '3') {
        wx.switchTab({
          url: '/pages/personal/personal'
        })
      }
    })
  },
  edit: function (e) {
    let id = e.currentTarget.dataset.id
    console.log(id)
    //  modifyContac 1 添加 2 编辑
    wx.navigateTo({
      url: `/pages/pets/pets?contact_id=${id}&modifyContac=2`
    })
  },

  btt: function (e) {
    let id = e.currentTarget.dataset.id
    console.log(id)
    //  modifyContac 1 添加 2 编辑
    wx.navigateTo({
      url: `/pages/pets/pets?modifyContac=1`
    })
  },
  choiceconter: function (e) {
    console.log(e.currentTarget.dataset.pets_id)
    let petsLisuiobj = {
      pets_id: e.currentTarget.dataset.pets_id,
      pet_name: e.currentTarget.dataset.pet_name,
      sculpture: e.currentTarget.dataset.sculpture,
      breed_name: e.currentTarget.dataset.breed_name,
    }
    app.globalData.petsLisui = petsLisuiobj
    wx.setStorageSync('petsLisuiobj', petsLisuiobj)
    app.globalData.petsLisui.is_refresh = true
    wx.navigateBack({
      delta: 1
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.main()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let that = this
    let share = {
      title: '快来查看我的爱宠！',
      // 如果不写path，那么分享出去的参数 逗号 , 会变成 %
      path: '/pages/petsLis/petsLis',
      success: function (res) {
        // 转发成功
        console.log("转发成功", res)
      },
      fail: function (err) {
        // 转发失败
        console.log("转发失败", err)
      }
    }
    return share
  }
})